package com.liyy.platform.other.mytest;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;

public class TestPaint
{
	public static void main(String [] args){
		new Tframe1().lunchframe();
	}
	
}

class Tframe1 extends Frame{
	
	ArrayList points=null;
	
	public void lunchframe(){
//		Frame f=new Frame("my is first frame");
		setBounds(200,200,400,400);
		points=new ArrayList();
		this.addMouseListener(new MouseMonitor());
		this.addWindowListener(new WindosMonitor());
		this.addKeyListener(new KeyMonitor());
		setVisible(true);
	}
	
     public void paint(Graphics g){
    	 Iterator i=points.iterator();
    	 while(i.hasNext()){
    		 Point p=(Point) i.next();
        	 g.setColor(Color.red);
        	 g.fillOval(p.x, p.y, 10, 10);
    	 }
     }
     public void addpoint(Point p){
    	 points.add(p);
     }
}

class MouseMonitor extends MouseAdapter{
	public void mousePressed(MouseEvent e){
		Tframe1 tf=(Tframe1) e.getSource();
		tf.addpoint(new Point(e.getX(),e.getY()));
		tf.repaint();
	}
}

class WindosMonitor extends WindowAdapter{
	public void windowClosing(WindowEvent e){
		Tframe1 tf=(Tframe1) e.getSource();
		tf.setVisible(false);
		System.exit(0);
	}
}

class KeyMonitor extends KeyAdapter{
	public void keyPressed(KeyEvent e){
		if(e.getKeyCode()==KeyEvent.VK_UP){
			System.out.println("up!!!");
		}
		}	
	}

